1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gdk.Event; 26 27 private import gdk.Device; 28 private import gdk.DeviceTool; 29 private import gdk.Display; 30 private import gdk.Seat; 31 private import gdk.Surface; 32 private import gdk.c.functions; 33 public import gdk.c.types; 34 private import gobject.ObjectG; 35 private import linker.Loader; 36 37 38 /** 39 * `GdkEvent`s are immutable data structures, created by GDK to 40 * represent windowing system events. 41 * 42 * In GTK applications the events are handled automatically by toplevel 43 * widgets and passed on to the event controllers of appropriate widgets, 44 * so using `GdkEvent` and its related API is rarely needed. 45 */ 46 public class Event 47 { 48 /** the main Gtk struct */ 49 protected GdkEvent* gdkEvent; 50 protected bool ownedRef; 51 52 /** Get the main Gtk struct */ 53 public GdkEvent* getEventStruct(bool transferOwnership = false) 54 { 55 if (transferOwnership) 56 ownedRef = false; 57 return gdkEvent; 58 } 59 60 /** the main Gtk struct as a void* */ 61 protected void* getStruct() 62 { 63 return cast(void*)gdkEvent; 64 } 65 66 /** 67 * Sets our main struct and passes it to the parent class. 68 */ 69 public this (GdkEvent* gdkEvent, bool ownedRef = false) 70 { 71 this.gdkEvent = gdkEvent; 72 this.ownedRef = ownedRef; 73 } 74 75 ~this () 76 { 77 if ( Linker.isLoaded(LIBRARY_GDK[0]) && ownedRef ) 78 gdk_event_unref(gdkEvent); 79 } 80 81 82 /** */ 83 public static GType getType() 84 { 85 return gdk_event_get_type(); 86 } 87 88 /** 89 * Returns the relative angle from @event1 to @event2. 90 * 91 * The relative angle is the angle between the X axis and the line 92 * through both events' positions. The rotation direction for positive 93 * angles is from the positive X axis towards the positive Y axis. 94 * 95 * This assumes that both events have X/Y information. 96 * If not, this function returns %FALSE. 97 * 98 * Params: 99 * event2 = second `GdkEvent` 100 * angle = return location for the relative angle between both events 101 * 102 * Returns: %TRUE if the angle could be calculated. 103 */ 104 public bool GetAngle(Event event2, out double angle) 105 { 106 return gdk_events_get_angle(gdkEvent, (event2 is null) ? null : event2.getEventStruct(), &angle) != 0; 107 } 108 109 /** 110 * Returns the point halfway between the events' positions. 111 * 112 * This assumes that both events have X/Y information. 113 * If not, this function returns %FALSE. 114 * 115 * Params: 116 * event2 = second `GdkEvent` 117 * x = return location for the X coordinate of the center 118 * y = return location for the Y coordinate of the center 119 * 120 * Returns: %TRUE if the center could be calculated. 121 */ 122 public bool GetCenter(Event event2, out double x, out double y) 123 { 124 return gdk_events_get_center(gdkEvent, (event2 is null) ? null : event2.getEventStruct(), &x, &y) != 0; 125 } 126 127 /** 128 * Returns the distance between the event locations. 129 * 130 * This assumes that both events have X/Y information. 131 * If not, this function returns %FALSE. 132 * 133 * Params: 134 * event2 = second `GdkEvent` 135 * distance = return location for the distance 136 * 137 * Returns: %TRUE if the distance could be calculated. 138 */ 139 public bool GetDistance(Event event2, out double distance) 140 { 141 return gdk_events_get_distance(gdkEvent, (event2 is null) ? null : event2.getEventStruct(), &distance) != 0; 142 } 143 144 /** 145 * Extracts all axis values from an event. 146 * 147 * To find out which axes are used, use [method@Gdk.DeviceTool.get_axes] 148 * on the device tool returned by [method@Gdk.Event.get_device_tool]. 149 * 150 * Params: 151 * axes = the array of values for all axes 152 * 153 * Returns: %TRUE on success, otherwise %FALSE 154 */ 155 public bool getAxes(out double[] axes) 156 { 157 double* outaxes; 158 uint nAxes; 159 160 auto __p = gdk_event_get_axes(gdkEvent, &outaxes, &nAxes) != 0; 161 162 axes = outaxes[0 .. nAxes]; 163 164 return __p; 165 } 166 167 /** 168 * Extract the axis value for a particular axis use from 169 * an event structure. 170 * 171 * To find out which axes are used, use [method@Gdk.DeviceTool.get_axes] 172 * on the device tool returned by [method@Gdk.Event.get_device_tool]. 173 * 174 * Params: 175 * axisUse = the axis use to look for 176 * value = location to store the value found 177 * 178 * Returns: %TRUE if the specified axis was found, otherwise %FALSE 179 */ 180 public bool getAxis(GdkAxisUse axisUse, out double value) 181 { 182 return gdk_event_get_axis(gdkEvent, axisUse, &value) != 0; 183 } 184 185 /** 186 * Returns the device of an event. 187 * 188 * Returns: a `GdkDevice` 189 */ 190 public Device getDevice() 191 { 192 auto __p = gdk_event_get_device(gdkEvent); 193 194 if(__p is null) 195 { 196 return null; 197 } 198 199 return ObjectG.getDObject!(Device)(cast(GdkDevice*) __p); 200 } 201 202 /** 203 * Returns a `GdkDeviceTool` representing the tool that 204 * caused the event. 205 * 206 * If the was not generated by a device that supports 207 * different tools (such as a tablet), this function will 208 * return %NULL. 209 * 210 * Note: the `GdkDeviceTool` will be constant during 211 * the application lifetime, if settings must be stored 212 * persistently across runs, see [method@Gdk.DeviceTool.get_serial]. 213 * 214 * Returns: The current device tool 215 */ 216 public DeviceTool getDeviceTool() 217 { 218 auto __p = gdk_event_get_device_tool(gdkEvent); 219 220 if(__p is null) 221 { 222 return null; 223 } 224 225 return ObjectG.getDObject!(DeviceTool)(cast(GdkDeviceTool*) __p); 226 } 227 228 /** 229 * Retrieves the display associated to the @event. 230 * 231 * Returns: a `GdkDisplay` 232 */ 233 public Display getDisplay() 234 { 235 auto __p = gdk_event_get_display(gdkEvent); 236 237 if(__p is null) 238 { 239 return null; 240 } 241 242 return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p); 243 } 244 245 /** 246 * Retuns the event sequence to which the event belongs. 247 * 248 * Related touch events are connected in a sequence. Other 249 * events typically don't have event sequence information. 250 * 251 * Returns: the event sequence that the event belongs to 252 */ 253 public GdkEventSequence* getEventSequence() 254 { 255 return gdk_event_get_event_sequence(gdkEvent); 256 } 257 258 /** 259 * Retrieves the type of the event. 260 * 261 * Returns: a `GdkEvent`Type 262 */ 263 public GdkEventType getEventType() 264 { 265 return gdk_event_get_event_type(gdkEvent); 266 } 267 268 /** 269 * Retrieves the history of the device that @event is for, as a list of 270 * time and coordinates. 271 * 272 * The history includes positions that are not delivered as separate events 273 * to the application because they occurred in the same frame as @event. 274 * 275 * Note that only motion and scroll events record history, and motion 276 * events do it only if one of the mouse buttons is down, or the device 277 * has a tool. 278 * 279 * Returns: an 280 * array of time and coordinates 281 */ 282 public GdkTimeCoord[] getHistory() 283 { 284 uint outNCoords; 285 286 auto __p = gdk_event_get_history(gdkEvent, &outNCoords); 287 288 return __p[0 .. outNCoords]; 289 } 290 291 /** 292 * Returns the modifier state field of an event. 293 * 294 * Returns: the modifier state of @event 295 */ 296 public GdkModifierType getModifierState() 297 { 298 return gdk_event_get_modifier_state(gdkEvent); 299 } 300 301 /** 302 * Returns whether this event is an 'emulated' pointer event. 303 * 304 * Emulated pointer events typically originate from a touch events. 305 * 306 * Returns: %TRUE if this event is emulated 307 */ 308 public bool getPointerEmulated() 309 { 310 return gdk_event_get_pointer_emulated(gdkEvent) != 0; 311 } 312 313 /** 314 * Extract the event surface relative x/y coordinates from an event. 315 * 316 * Params: 317 * x = location to put event surface x coordinate 318 * y = location to put event surface y coordinate 319 */ 320 public bool getPosition(out double x, out double y) 321 { 322 return gdk_event_get_position(gdkEvent, &x, &y) != 0; 323 } 324 325 /** 326 * Returns the seat that originated the event. 327 * 328 * Returns: a `GdkSeat`. 329 */ 330 public Seat getSeat() 331 { 332 auto __p = gdk_event_get_seat(gdkEvent); 333 334 if(__p is null) 335 { 336 return null; 337 } 338 339 return ObjectG.getDObject!(Seat)(cast(GdkSeat*) __p); 340 } 341 342 /** 343 * Extracts the surface associated with an event. 344 * 345 * Returns: The `GdkSurface` associated with the event 346 */ 347 public Surface getSurface() 348 { 349 auto __p = gdk_event_get_surface(gdkEvent); 350 351 if(__p is null) 352 { 353 return null; 354 } 355 356 return ObjectG.getDObject!(Surface)(cast(GdkSurface*) __p); 357 } 358 359 /** 360 * Returns the timestamp of @event. 361 * 362 * Not all events have timestamps. In that case, this function 363 * returns %GDK_CURRENT_TIME. 364 * 365 * Returns: timestamp field from @event 366 */ 367 public uint getTime() 368 { 369 return gdk_event_get_time(gdkEvent); 370 } 371 372 alias doref = ref_; 373 /** 374 * Increase the ref count of @event. 375 * 376 * Returns: @event 377 */ 378 public Event ref_() 379 { 380 auto __p = gdk_event_ref(gdkEvent); 381 382 if(__p is null) 383 { 384 return null; 385 } 386 387 return ObjectG.getDObject!(Event)(cast(GdkEvent*) __p, true); 388 } 389 390 /** 391 * Returns whether a `GdkEvent` should trigger a context menu, 392 * according to platform conventions. 393 * 394 * The right mouse button typically triggers context menus. 395 * 396 * This function should always be used instead of simply checking for 397 * event->button == %GDK_BUTTON_SECONDARY. 398 * 399 * Returns: %TRUE if the event should trigger a context menu. 400 */ 401 public bool triggersContextMenu() 402 { 403 return gdk_event_triggers_context_menu(gdkEvent) != 0; 404 } 405 406 /** 407 * Decrease the ref count of @event. 408 * 409 * If the last reference is dropped, the structure is freed. 410 */ 411 public void unref() 412 { 413 gdk_event_unref(gdkEvent); 414 } 415 }